package com.example.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.pojo.User;
import com.example.service.FUserService;
import com.example.utils.MD5Utils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller

public class UserController {

    @Reference
    private FUserService FUserService;
    //登录
    @RequestMapping("/login")
    public String login(HttpSession session,String uid, String upwd){
        User user =null;
        try {
            user=FUserService.login(uid,upwd);
        }catch (Exception e){
            System.out.println("出错了");
        }

        //2.判断
        if(user != null){
            session.setAttribute("loginUser",user);
            if (user.getPassword().equals(MD5Utils.md5(upwd))){
                System.out.println("密码正确，登录成功！");
                return "redirect:/GoodsController/GetAll";
            }else{
                System.out.println("密码错误，登陆失败！");
                return "login";
            }
        }else{
            System.out.println("用户不存在，请重新输入！");
            return "login";
        }
    }







    @RequestMapping("/tuichu")
    public String tuichu(HttpSession session){
        if (session!=null){
            //清除系统所有的session变量
            session.invalidate();
        }
        return "redirect:/login.jsp";
    }


}
